const $request = (url, data, method = 'POST', headers = "application/json;", token, flag) => {
	return new Promise((resolve, reject) => {
		let port = 'http://www.apiurl.cn' //接口请求地址

		let upData = data
		if (url != '/portal/mealDuration/list' && url != '/portal/inform/list') {
			upData.pluginId = 'app'
		}

		let headerS = {
			'Content-Type': 'application/json;'
		}
		if (token) {
			headerS.Authorization = token
		}

		uni.request({
			url: port + url,
			method: method,
			data: upData,
			header: headerS,
			success(res) {
				if (res.data.code == 401) {
					uni.navigateTo({
						url: '/pages/mine/login'
					})
					return false
				}
				resolve(res)
				uni.hideLoading(); //关闭loading
			},
			fail(error) {
				reject(error);
				// throw new Error(error);
				uni.hideLoading(); //关闭loading
			},
			complete() {
				uni.hideLoading(); //关闭loading
			}
		})
	})
}
//get请求
const $get = (url, data, token) => {
	return $request(url, data, 'GET', '', token)
}
//post请求
const $post = (url, data, token) => {
	return $request(url, data, 'POST', '', token)
}
//给uniapp原生的requset赋值
//记得要在mian.js中引用
uni.$request = $request
uni.$get = $get
uni.$post = $post
